import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'


function fetchUser(){
    return fetch('/api/login')
}

function* fetchUser(action) {
    try {
        const user = yield call(fetchUser, action.payload);
        yield put({type: "USER_FETCH_SUCCESS", payload: user});
    } catch (e) {
        yield put({type: "USER_FETCH_FAILD", message: e.message});
    }
}

function* mySaga() {
    yield takeLatest("USER_FETCH_REQUESTED", fetchUser);
}

export default mySaga;